package com.longcai.bean;

/**
 * 返回的参数封装类
 *
 * @author zhaojie
 * @Title: APIResponse
 * @ProjectName
 * @Description: TODO
 * @date 2018/12/2815:16
 */
public class ApiResult<T> {

    private static final String CODE_SUCCESS = "success";

    private static final String CODE_FAIL = "fail";

    private String code;
    private T data;
    private String msg;

    public ApiResult() {
    }

    public ApiResult(String code) {
        this.code = code;
    }

    public ApiResult(String code, T data) {
        this.code = code;
        this.data = data;
    }

    public ApiResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ApiResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ApiResult success() {
        return new ApiResult(CODE_SUCCESS);
    }

    public static ApiResult success(Object data) {
        return new ApiResult(CODE_SUCCESS, data);
    }

    public static ApiResult fail(Object data) {
        return new ApiResult(CODE_FAIL, data);
    }

    public static ApiResult fail(String msg) {
        return new ApiResult(CODE_FAIL, msg);
    }

    public static ApiResult fail(String msg, Object data) {
        return new ApiResult(CODE_FAIL, msg, data);
    }

    public static ApiResult success(String msg, Object data) {
        return new ApiResult(CODE_SUCCESS, msg, data);
    }

    public static ApiResult widthCode(String errorCode) {
        return new ApiResult(errorCode);
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
